home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / pibasy47.zip / PIBTIMER.PAS < prev    next >
Pascal/Delphi Source File  |  1988-03-21  |  9KB  |  195 lines

  1. UNIT PibTimer;
  2.  
  3. INTERFACE
  4.  
  5. USES
  6.    Dos, GlobType;
  7.  
  8.    FUNCTION TimeOfDay : LONGINT;
  9.    FUNCTION TimeDiff( Timer1, Timer2: LONGINT ) : LONGINT;
  10.  
  11.    FUNCTION TimeOfDayH : LONGINT;
  12.    FUNCTION TimeDiffH( Timer1, Timer2: LONGINT ) : LONGINT;
  13.  
  14. IMPLEMENTATION
  15.  
  16. (*--------------------------------------------------------------------------*)
  17. (*                TimeOfDay  --- Get time of day                            *)
  18. (*--------------------------------------------------------------------------*)
  19.  
  20. FUNCTION TimeOfDay : LONGINT;
  21.  
  22. (*--------------------------------------------------------------------------*)
  23. (*                                                                          *)
  24. (*     Function:  TimeOfDay                                                 *)
  25. (*                                                                          *)
  26. (*     Purpose:   Gets time of day from internal clock                      *)
  27. (*                                                                          *)
  28. (*     Calling sequence:                                                    *)
  29. (*                                                                          *)
  30. (*        Tod := TimeOfDay : LONGINT;                                       *)
  31. (*                                                                          *)
  32. (*           Tod --- Long integer number which is timer value expressed in  *)
  33. (*                   seconds as:                                            *)
  34. (*                   ( 3600 x hour + 60 x minutes + seconds )               *)
  35. (*                                                                          *)
  36. (*     Calls:  GetTime                                                      *)
  37. (*                                                                          *)
  38. (*--------------------------------------------------------------------------*)
  39.  
  40. VAR
  41.    Hours   : WORD;
  42.    Minutes : WORD;
  43.    Seconds : WORD;
  44.    SecHun  : WORD;
  45.  
  46.    TimeVal : LONGINT;
  47.  
  48. BEGIN (* TimeOfDay *)
  49.  
  50.    GetTime( Hours, Minutes, Seconds, SecHun );
  51.  
  52.    TimeVal    := Hours;
  53.    TimeOfDay  := TimeVal * 3600 + Minutes * 60 + Seconds;
  54.  
  55. END   (* TimeOfDay *);
  56.  
  57. (*--------------------------------------------------------------------------*)
  58. (*        TimeDiff  --- Get difference in time between two timer values     *)
  59. (*--------------------------------------------------------------------------*)
  60.  
  61. FUNCTION TimeDiff( Timer1, Timer2: LONGINT ) : LONGINT;
  62.  
  63. (*--------------------------------------------------------------------------*)
  64. (*                                                                          *)
  65. (*     Function:  TimeDiff                                                  *)
  66. (*                                                                          *)
  67. (*     Purpose:   Get difference in time between two timer values in        *)
  68. (*                seconds.                                                  *)
  69. (*                                                                          *)
  70. (*     Calling sequence:                                                    *)
  71. (*                                                                          *)
  72. (*        TDiff := TimeDiff( Timer1, Timer2: LONGINT ) : LONGINT;           *)
  73. (*                                                                          *)
  74. (*           Timer1  --- first timer value (earlier)                        *)
  75. (*           Timer2  --- second timer value (later)                         *)
  76. (*                                                                          *)
  77. (*           TDiff   --- difference between timer values                    *)
  78. (*                                                                          *)
  79. (*     Calls:  None                                                         *)
  80. (*                                                                          *)
  81. (*     Remarks:                                                             *)
  82. (*                                                                          *)
  83. (*        This routine will handle time wrap around midnight.  However, it  *)
  84. (*        only handles timer values <= 24 hours in duration.                *)
  85. (*                                                                          *)
  86. (*--------------------------------------------------------------------------*)
  87.  
  88. CONST
  89.    Secs_Per_Day = 86400    (* Seconds in one day *);
  90.  
  91. VAR
  92.    TDiff : LONGINT;
  93.  
  94. BEGIN (* TimeDiff *)
  95.  
  96.    TDiff := Timer2 - Timer1;
  97.  
  98.    IF ( TDiff < 0 ) THEN
  99.       TDiff := TDiff + Secs_Per_Day;
  100.  
  101.    TimeDiff := TDiff;
  102.  
  103. END   (* TimeDiff *);
  104.  
  105. (*--------------------------------------------------------------------------*)
  106. (*      TimeOfDayH  --- Get time of day in 1/100 seconds from midnight      *)
  107. (*--------------------------------------------------------------------------*)
  108.  
  109. FUNCTION TimeOfDayH : LONGINT;
  110.  
  111. (*--------------------------------------------------------------------------*)
  112. (*                                                                          *)
  113. (*     Function:  TimeOfDayH                                                *)
  114. (*                                                                          *)
  115. (*     Purpose:   Gets time of day from internal clock in 1/100 seconds     *)
  116. (*                                                                          *)
  117. (*     Calling sequence:                                                    *)
  118. (*                                                                          *)
  119. (*        Tod := TimeOfDayH : LONGINT;                                      *)
  120. (*                                                                          *)
  121. (*           Tod --- Real number which is timer value expressed in          *)
  122. (*                   hundredths of seconds as:                              *)
  123. (*                   ( 360000 x hour + 6000 x minutes + 100 x seconds +     *)
  124. (*                     hundredths of seconds ).                             *)
  125. (*                                                                          *)
  126. (*     Calls:  GetTime                                                      *)
  127. (*                                                                          *)
  128. (*--------------------------------------------------------------------------*)
  129.  
  130. VAR
  131.    Hours   : WORD;
  132.    Minutes : WORD;
  133.    Seconds : WORD;
  134.    SecHun  : WORD;
  135.  
  136.    TimerVal: LONGINT;
  137.  
  138. BEGIN (* TimeOfDayH *)
  139.  
  140.    GetTime( Hours, Minutes, Seconds, SecHun );
  141.  
  142.    TimerVal    := Hours;
  143.    TimeOfDayH  := TimerVal * 360000 + Minutes * 6000 + Seconds * 100 + SecHun;
  144.  
  145. END   (* TimeOfDayH *);
  146.  
  147. (*--------------------------------------------------------------------------*)
  148. (*       TimeDiffH  --- Get difference in time between two timer values     *)
  149. (*--------------------------------------------------------------------------*)
  150.  
  151. FUNCTION TimeDiffH( Timer1, Timer2: LONGINT ) : LONGINT;
  152.  
  153. (*--------------------------------------------------------------------------*)
  154. (*                                                                          *)
  155. (*     Function:  TimeDiffH                                                 *)
  156. (*                                                                          *)
  157. (*     Purpose:   Get difference in time between two timer values           *)
  158. (*                in hundredths of seconds.                                 *)
  159. (*                                                                          *)
  160. (*     Calling sequence:                                                    *)
  161. (*                                                                          *)
  162. (*        Tdiff := TimeDiffH( Timer1, Timer2: LONGINT ) : REAL;             *)
  163. (*                                                                          *)
  164. (*           Timer1  --- first timer value (earlier)                        *)
  165. (*           Timer2  --- second timer value (later)                         *)
  166. (*                                                                          *)
  167. (*           Tdiff   --- difference between timer values                    *)
  168. (*                                                                          *)
  169. (*     Calls:  None                                                         *)
  170. (*                                                                          *)
  171. (*     Remarks:                                                             *)
  172. (*                                                                          *)
  173. (*        This routine will handle time wrap around midnight.  However, it  *)
  174. (*        only handles timer values <= 24 hours in duration.                *)
  175. (*                                                                          *)
  176. (*--------------------------------------------------------------------------*)
  177.  
  178. CONST
  179.    Hundredths_Secs_Per_Day = 8640000    (* 1/100 Seconds in one day *);
  180.  
  181. VAR
  182.    TDiff : LONGINT;
  183.  
  184. BEGIN (* TimeDiffH *)
  185.  
  186.    TDiff := Timer2 - Timer1;
  187.  
  188.    IF Tdiff < 0 THEN Tdiff := Tdiff + Hundredths_Secs_Per_Day;
  189.  
  190.    TimeDiffH := Tdiff;
  191.  
  192. END   (* TimeDiffH *);
  193.  
  194. END (* PibTimer *).
  195.